package xy.donate.android.ui.activity;

import android.content.Intent;
import android.view.View;

import com.tencent.imsdk.v2.V2TIMConversation;
import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo;
import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationLayout;
import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationListLayout;
import com.tencent.qcloud.tim.uikit.modules.conversation.base.ConversationInfo;

import xy.donate.android.R;
import xy.donate.android.common.MyActivity;
import xy.donate.android.constant.Constant;

public class ConversationListActivity extends MyActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_conversation_list;
    }

    @Override
    protected void initView() {
        ConversationLayout conversationLayout = findViewById(R.id.conversation_list);
        conversationLayout.initDefault();
        conversationLayout.getConversationList().setOnItemClickListener((view, i, conversationInfo) -> {
            startChatActivity(conversationInfo);
        });
    }

    @Override
    protected void initData() {

    }

    private void startChatActivity(ConversationInfo conversationInfo){
        ChatInfo chatInfo = new ChatInfo();
        chatInfo.setType(V2TIMConversation.V2TIM_C2C);
        chatInfo.setId(conversationInfo.getId());
        chatInfo.setChatName(conversationInfo.getTitle());
        Intent intent = new Intent(this,ChatDetailActivity.class);
        intent.putExtra(Constant.CHAT_INFO,chatInfo);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    //    private fun startChatActivity(conversationInfo: ConversationInfo) {
    //        val chatInfo = ChatInfo()
    //        chatInfo.type =
    //            if (conversationInfo.isGroup) V2TIMConversation.V2TIM_GROUP else V2TIMConversation.V2TIM_C2C
    //        chatInfo.id = conversationInfo.id
    //        chatInfo.chatName = conversationInfo.title
    //        val intent = Intent(BaseApplication.getInstance(), ChatActivity::class.java)
    //        intent.putExtra(Constants.CHAT_INFO, chatInfo)
    //        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    //        startActivity(intent)
    //    }
}